﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Jinndev {

    public class FPS : MonoBehaviour {

        public Text text;
        public float fps;
        public string format = "{0} fps";

        private float timer = 0;
        private float frames = 0;

        private void OnEnable() {
            if(text == null) {
                text = GetComponent<Text>();
            }
        }

        private void Update() {
            frames++;
            timer += Time.deltaTime;

            if(timer > 1) {
                timer %= 1;
                fps = frames;
                frames = 0;
                if (text != null && format != null) {
                    text.text = string.Format(format, fps);
                }
            }
        }


    }

}